(function(a){
	a.fn.toggleSidebar=function(c){
		c=a.extend({
			expand:"#main-wrapper",
			hideText:"(-)",
			showText:"(+)",
			animated:true,
			animateSpeed:400,
			extraWidth:0,
			easingType:null,
			enableCookie:false,
			cookieName:"sidebar-session",
			expires:7000,
			insertNav:true,
			defaultHidden:false
		},c);
	
	a(c.expand).before(
		c.insertNav?'<div id="sidebar-toggler-wrapper"><a class="sidebar-toggler from-js" href="#">'+c.hideText+'</a><div style="clear:both;"></div></div>':"");
		var g=this,
			d=a(".sidebar-toggler"),
			e=g.outerWidth(true)+c.extraWidth,
			b=a(c.expand).width(),
			f={createCookie:function(j,k,l){
				if(l){var i=new Date();
					i.setTime(i.getTime()+(l*24*60*60*1000));
					var h="; expires="+i.toGMTString()
				}else{
					var h=""
				}
				document.cookie=j+"="+k+h+"; path=/"
			},
			
			readCookie:function(j){
				var l=j+"=";
				var h=document.cookie.split(";");
				for(var k=0;k<h.length;k++){
					var m=h[k];
					while(m.charAt(0)==" "){m=m.substring(1,m.length)}
					if(m.indexOf(l)==0){return m.substring(l.length,m.length)}
				}
				return null
			},
			
			eraseCookie:function(h){
				this.createCookie(h,"",-1)
			},
			
			hideSidebar:function(){
				d.addClass("active").html(c.showText);
				if(c.animated){
					g.stop(true,true).fadeOut(c.animateSpeed/2,function(){
						a(c.expand).animate({width:b+e},c.animateSpeed,c.easingType)
					})
				}else{
					g.hide();
					a(c.expand).css("width",b+e)
				}
				if(c.enableCookie){
					if(!c.defaultHidden){
						this.createCookie(c.cookieName,null,c.expires)
					}else{
						this.eraseCookie(c.cookieName)
					}
				}
			},
			
			showSidebar:function(){
				d.removeClass("active").html(c.hideText);
				if(c.animated){
					a(c.expand).stop().animate({width:b},c.animateSpeed,c.easingType,function(){
						g.fadeIn(c.animateSpeed)
					})
				}else{
					g.show();
					a(c.expand).css("width",b)
				}
				if(c.enableCookie){
				if(!c.defaultHidden){
					this.eraseCookie(c.cookieName)
				}else{
					this.createCookie(c.cookieName,null,c.expires)}
				}
			}
			};
			
			d.on("click",function(){
				f[g.is(":hidden")?"showSidebar":"hideSidebar"]();
				return false});
				if(c.defaultHidden){
					g[f.readCookie(c.cookieName)?"show":"hide"]();
					a(c.expand).css("width",(f.readCookie(c.cookieName)?b:b+e));
					f[!f.readCookie(c.cookieName)?"hideSidebar":"showSidebar"]()
				}else{
					g[f.readCookie(c.cookieName)?"hide":"show"]();
					a(c.expand).css("width",(f.readCookie(c.cookieName)?b+e:b));
					f[f.readCookie(c.cookieName)?"hideSidebar":"showSidebar"]()
				}
	}
})(jQuery);